Ext.extend(app.module,{
    currentFormValues: {},
    init: function(){
        mainPanel = this;
        this.crossbshDs = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({url:'crossproject/listforsh.do'}),
            reader: new Ext.data.JsonReader({
                totalProperty: 'total',
                root: 'rows',
                idProperty: 'id'
            },[
                {name:'id'},
                {name:'name'},
                {name:'description'},
                {name:'projecttype'},
                {name:'state'},
                {name:'reporttime'},
                {name:'approvaltime'},
                {name:'planendtime'},
                {name:'endtime'},
                {name:'tasktime'},
                {name:'middletime'},
                {name:'finishtime'},
                {name:'filepath'},
                {name:'taskpath'},
                {name:'remain'},
                {name:'filename'},
                {name:'projectTypeName'},
                {name:'iscross'},
                {name:'approvedept'},
                {name:'rank'},
                {name:'shoolmoney'},
                {name:'remarks'},
                {name:'deptname'},
                {name:'names'},
                {name:'isleader'},
                {name:'isagree'},
                {name:'yjpath'},
                {name:'expertCount'},
                {name:'agreeCount'},
                {name:'disagreeCount'}
            ])
        });
        var crossbsh_pagesize_combo = new Ext.form.ComboBox( {       //设置分页栏的每页记录数选择
            name : 'pagesize',
            hiddenName : 'pagesize',
            typeAhead : true,
            triggerAction : 'all',
            lazyRender : true,
            mode : 'local',
            store : new Ext.data.ArrayStore(
                {
                    fields : [ 'value', 'text' ],
                    data : [ [ 20, '20条/页' ],[ 50, '50条/页' ], [ 100, '100条/页' ],[ 200, '250条/页' ]]
                }),
            valueField : 'value',
            displayField : 'text',
            value : '20',
            editable : false,
            width : 85
        });
        var number = parseInt(crossbsh_pagesize_combo.getValue());

        crossbsh_pagesize_combo.on("select", function(comboBox) {
            var bbar = Ext.getCmp('crossbshbbar');
            bbar.pageSize = parseInt(comboBox.getValue());
            number = parseInt(comboBox.getValue());
            mainPanel.crossbshDs.reload( {
                params : {
                    start : 0,
                    limit : bbar.pageSize
                }
            });
        });
        this.body = new Ext.grid.GridPanel({
            store: this.crossbshDs,
            region: 'center',
            loadMask: true,
            viewConfig:{
                forceFit:true
            },
            columns: [
                new Ext.grid.RowNumberer(),
                {
                    xtype: 'numbercolumn',
                    dataIndex: 'id',
                    header: 'id',
                    hidden: true
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'name',
                    header: '点击课题名称查看',
                    renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
                        return '<a href="javascript:void(0)" onclick="mainPanel.getFileViewDlg('+
                            record.data["id"]+')">'+value+'</a>';
                    }
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'approvedept',
                    header: '联合部门'
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'names',
                    header: '负责人',
                    renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
                        if(value.indexOf(",")==-1){
                            return value;
                        } else {
                            return value.substring(0,value.indexOf(","));
                        }
                    }
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'deptname',
                    header: '负责人部门'
                },
                {
                    xtype: 'actioncolumn',
                    width: 50,
                    header: '审核通过',
                    align: 'center',
                    items: [
                        {
                            icon: '../images/ext/accept.png',
                            tooltip: '审核通过',
                            handler: function(grid, rowIndex, colIndex) {
                                var record = grid.getStore().getAt(rowIndex);
                                Ext.Msg.confirm('审核通过', '确定同意课题<font color="red">' + record.data.name + '</font>立项',
                                    function(btn) {
                                        if (btn == 'yes') {
                                            mainPanel.submitProjectCross(record.data.id,1);
                                        }
                                    }
                                );
                            }
                        },
                        {
                            icon: '../images/ext/delete.png',
                            tooltip: '审核不通过',
                            handler: function(grid, rowIndex, colIndex) {
                                var record = grid.getStore().getAt(rowIndex);
                                Ext.Msg.confirm('审核不通过', '确定不同意课题<font color="red">' + record.data.name + '</font>立项',
                                    function(btn) {
                                        if (btn == 'yes') {
                                            mainPanel.submitProjectCross(record.data.id,0);
                                        }
                                    }
                                );
                            }
                        }
                    ]
                }
            ],
            bbar: {
                id: 'crossbshbbar',
                xtype: 'paging',
                pageSize : number,
                store : this.crossbshDs,
                displayInfo : true,
                displayMsg : '显示{0}条到{1}条,共{2}条',
                emptyMsg : "没有符合条件的记录",
                items : [ '-', '&nbsp;&nbsp;', crossbsh_pagesize_combo ]
            }
        });
        this.main.add(this.body);
        this.main.doLayout();
        this.crossbshDs.load({
            params: {start:0, limit:20 }
        });
    },
    submitProjectCross: function(projectid,isagree){
        mainPanel = this;
        Ext.Ajax.request({
            method:'post',
            url:'crossproject/submitProjectCross.do',
            params:{
                isagree:isagree,
                projectid:projectid
            },
            success: function(resp, opts) {
                var result = Ext.util.JSON.decode(resp.responseText);
                var info = result.info;
                if(result.success=='true') {
                    mainPanel.crossbshDs.reload();
                    Ext.Msg.alert('信息', info);
                }else {
                    Ext.Msg.alert('信息', info);
                }
            },
            failure: function(resp,opts) {
                var result = Ext.util.JSON.decode(resp.responseText);
                var info = result.info;
                Ext.Msg.alert('提示', info);
            }
        });
    }
});
